package com.nas.crocus.dao.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nas.crocus.dao.HotelDao;
import com.nas.crocus.domain.Evento;
import com.nas.crocus.domain.Hotel;

@Repository
public class HotelDaoImp implements HotelDao{

    @Autowired
    private SessionFactory sessionFactory;
    
    @Override
    public Hotel buscar(Long alojamientoId) {
        return (Hotel) sessionFactory.getCurrentSession().get(Hotel.class,
                alojamientoId);
    }

    @Override
    public Collection<Hotel> buscar() {
        Session session = sessionFactory.getCurrentSession();        
        return session.createCriteria(Hotel.class).list();
    }

    @Override
    public void guardar(Hotel hotel) {
        sessionFactory.getCurrentSession().save(hotel);  
        
    }

    @Override
    public void actualizar(Hotel hotel) {
        sessionFactory.getCurrentSession().update(hotel);  
    }

    @Override
    public Hotel buscarPorNombre(String nombre) {
        Session session = sessionFactory.getCurrentSession();        
        Criteria crit=session.createCriteria(Hotel.class);
        crit.add(Restrictions.eq("nombre",nombre).ignoreCase());
        
        return (Hotel) crit.uniqueResult();
    }

}
